package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 套餐管理
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageList(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult pageResult = setmealService.pageList(setmealPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> findById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.findById(id);

        return Result.success(setmealVO);
    }

    /**
     * 套餐起售、停售
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(Long id, @PathVariable Integer status) {
        setmealService.updateStatus(id, status);

        return Result.success();
    }

    /**
     * 新增套餐
     * @return
     */
    @PostMapping
    public Result<String> add(@RequestBody SetmealDTO setmealDTO) {
        setmealService.add(setmealDTO);

        return Result.success();
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping
    public Result<String> updateInfo(@RequestBody SetmealDTO setmealDTO) {
        setmealService.updateInfo(setmealDTO);

        return Result.success();
    }

    /**
     * 批量删除套餐
     * @return
     */
    @DeleteMapping
    public Result<String> delete(Long[] ids) {
        setmealService.delete(ids);

        return Result.success();
    }
}